﻿using System;
using MediaPortal.GUI.Library;
using System.Windows.Forms;
using MyMenu.config;
using MyMenuSetup;
using MediaPortal.Configuration;
namespace MyMenu
{
    public class MyMenu : GUIWindow, ISetupForm
    {

        action.Action menuPrincipalAction;

        bool shwown = false;

        int keyChar;
        public string PluginName()
        {
            return "MyMenu";
        }


        public string Description()
        {
            return "A personal menu, with custom actions called from any screen with a keyboard key or remote action";
        }

        public string Author()
        {
            return "Packstlaurent";
        }

        public void ShowPlugin()
        {
            new Form1(Config.GetFile(Config.Dir.Config, "myMenu.xml")).Show();
        }

        public bool CanEnable()
        {
            return true;
        }

        public int GetWindowId()
        {
            return 5678;
        }

        public bool DefaultEnabled()
        {
            return true;
        }

        public bool HasSetup()
        {
            return true;
        }

        public bool GetHome(out string strButtonText, out string strButtonImage,
             out string strButtonImageFocus, out string strPictureImage)
        {
            strButtonText = String.Empty;
            strButtonImage = String.Empty;
            strButtonImageFocus = String.Empty;
            strPictureImage = String.Empty;
            return false;
        }

        public override bool Init()
        {
            menuPrincipalAction = config.XmlParseur.getFirstAction(Config.GetFile(Config.Dir.Config, "myMenu.xml"));
            GUIGraphicsContext.OnNewAction += new OnActionHandler(OnAction);
            keyChar = Int32.Parse(menuPrincipalAction.keyChar);
                       
            return true;
        }

        public override void OnAction(MediaPortal.GUI.Library.Action action){
        
        
            if (action.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_KEY_PRESSED) //user navigated down (key-down or remote-down or...
            {
               //action.w
                int key = action.m_key.KeyChar;
              
                if (keyChar.Equals(key))
                {
                        menuPrincipalAction.execute();
                        shwown = true;
                }
            }
        }




        // With GetID it will be an window-plugin / otherwise a process-plugin
        // Enter the id number here again
        public override int GetID
        {
            get
            {
                return 5678;
            }

            set
            {
            }
        }

    }

}
